// pages/paySuccess/paySuccess.js

var app = getApp();
var page = 1;
var selectedNews = false;
var newsList = [];
import {
  update_user_status,
  get_carte
} from "../../utils/api.js";

Page({
  data: {
    id: "",
    price: ""
  },
  //编辑名片
  editCard: function () {
    wx.redirectTo({
      url: '/pages/editCarte/editCarte',
    })
  },
  //回到首页
  backHome: function() {
    wx.switchTab({
      url: '/pages/carteShow/carteShow',
    })
  },
  backPerson:function(){
    wx.switchTab({
      url: '/pages/person/person',
    })
  },
  //点击查看订单进入订单详情页面
  showOrder: function(e) {
    wx.redirectTo({
      // url: '../orderDetail/orderDetail?id=' + this.data.id.
      url:'/pages/myOrders/myOrders'
    })
  },
  onLoad: function(options) {
    // 页面初始化 options为页面跳转所带来的参数
    // console.log(options)
    var that = this;
    that.setData({
      price: options.price,
      type: options.type,
      id: options.id,
      carte_id: options.carte_id
    })
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
    if (this.data.type == 1) {
      // this.updateUserStatus()
    }
  },
  // 改变用户购买状态
  updateUserStatus: function name() {
    const that = this
    const uid = app.globalData.userInfo.id
    app.HttpGetSend(
      update_user_status, {
        uid: uid,
        parent_id: that.data.carte_id,
        invite_id: app.globalData.shareOptions.share_id ? app.globalData.shareOptions.share_id : ''
      },
      function(res) {
        // console.log(res)
        if (res.msg != "success") {
          app.showTipMsg(res.msg);
        } else {
          console.log(res)
          app.HttpGetSend(
            get_carte, {
              uid: uid,
              v_id: uid
            },
            function(result_data) {
              // console.log(res)
              if (result_data.msg != "success") {
                app.showTipMsg(result_data.msg);
              } else {
                app.globalData.userInfo = { ...result_data.data
                }
                wx.setStorage({
                  key: 'userInfo',
                  data: JSON.stringify({ ...result_data.data
                  })
                })
              }
            })
        }
      })
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  },
  // onShareAppMessage: function() {
  //   return {
  //     title: '万商名片',
  //     desc: '你要的名片',
  //     path: '/pages/carteFavorites/carteFavorites'
  //   }
  // },
  /** 
   * 页面上拉触底事件的处理函数 
   */
  onReachBottom: function() {

  }
})